<?php
class NewsModel extends CommonModel {
    public $muser;
    public $member;
	public function _list_($map = '' ,$page = 1,$limit = 16, $orderby = ' id desc'){
        $list['count'] = $this->where($map)->count('id');
        $list['page'] = $page;
        $list['map'] = $map;
        $list['limit'] = $limit;
        $pagecount = ceil($list['count'] / $list['limit']);
        if ($pagecount < 1) $pagecount =1;
        $list['pagecount'] = $pagecount;
        $vlist   =   $this->where($map)->page($page,$limit)->order(" $orderby ")->select();
        $volist = array();
        foreach ($vlist as $key) {
        	$key['top_text'] = $this->geTop($key['top']);
        	$key['help_text'] = $this->getHelp($key['ishelp']);
        	$key['welcome_text'] = $this->getWelcome($key['iswelcome']);
        	$volist[] = $key;
        }
        $list['volist']   =   $volist;
        return $list;
    }

    public function _list($map, $page = 1, $limit = 10) {
        if ($map['tid'] == 0) unset($map['tid']);
        $list   =   $this->where($map)->page($page,$limit)->order('id desc')->select();
        $vlist = array();
        foreach($list as $v){
            if (!$v['url']) {
                // /$vars='',$suffix=true,$redirect=false,$domain=false
                $v['url'] = U("Mobile/News/view?id=$v[id]",'',true,false,true);
            }
            $vlist[] = $v;
        }
        return $vlist;
    }

    public function getWelcome($iswelcome = 0)
    {
    	if ($iswelcome == 1) {
    		return "关注回复";
    	}
    	return "";
    }

    public function getHelp($ishelp = 0)
    {
    	if ($ishelp == 1) {
    		return "自动回复";
    	}
    	return "";
    }

    public function geTop($top = 0)
    {
    	if ($top >0 && $top <= 10 ) {
    		return "局部置顶".$top;
    	}elseif ($top >11 && $top <= 20) {
    		return "全局置顶".$top;
    	}elseif ($top >21 && $top <= 30) {
    		return "局部置底".$top;
    	}elseif ($top >31 && $top <= 40) {
    		return "全局置底".$top;
    	}
    	return "";
    }

    public function getStatus()
    {
    	# code...
    }

    public function top($map, $page = 1, $limit = 5) {
        if ($map['tid'] == 0) unset($map['tid']);
        $subdemain = $map['subdemain'];
        unset($map['subdemain']);
        $list   =   $this->where($map)->page($page,$limit)->order('top,id desc')->select();
        $vlist = array();
        foreach($list as $v){
            if (!$v['url']) {
                $v['url'] = U("Mobile/News/view?id=$v[id]",'',true,false,true);
            }
            $vlist[] = $v;
        }
        return $vlist;
    }

}